﻿Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
FantastPlatform.UI.HousePersonAddPanel = function (config) {
    Ext.apply(this, config);

    var baseInfoGrid = new Ext.form.FormPanel({
        border: false,
        split: true,
        labelWidth: 80,
        labelAlign: 'right',
        collapsible: true,
        items: [{
            layout: 'column',
            border: false,
            labelSeparator: '：',
            items: [{
                columnWidth: 0.5,
                border: false,
                layout: 'form',
                items: [new Ext.form.Hidden({
                    name: 'CreatePoliceManNumber'
                })]
            }]
        }]
    });
    this.HousePersonAddForm = baseInfoGrid;

    var houseId = this.Id;
    var editGrid = new FantastPlatform.UI.AddPersonGrid({
        height: 380,
        tbar: [{
            text: '添加',
            iconCls: 'add',
            id:'addHousePerson',
            tooltip: {
                text: '添加住户信息',
                title: '添加住户信息',
                autoHide: true
            },
            handler: function () { editGrid.onAddPersonFClick(houseId); }
        }, '-', {
            text: '编辑',
            iconCls: 'edit',
            id: 'editHousePerson',
            tooltip: {
                text: '编辑住户',
                title: '编辑住户',
                autoHide: true
            },
            handler: function () { editGrid.onEditPersonFClick(houseId); }
        }, '-', {
            text: '移除',
            iconCls: 'delete',
            id: 'deleteDetail',
            handler: function () {
                var node = checkGridSelected(editGrid);
                if (node) {
                    var id = '';
                    for (var i = 0; i < node.length; i++) {
                        if (node[i].get('Id') == 0) {
                            editGrid.store.remove(node[i]);
                        } else {
                            id += node[i].get('Id') + ",";
                        }
                    }                  
                    id = id.substring(0, id.length - 1);
                    if (id && id != '' && id != null) {
                        Ext.Msg.confirm('提示', '确认要移除选中的数据吗？', function (btn) {
                            if (btn == 'yes') {
                                Ext.Msg.wait('正在移除数据，请稍候……', '移除数据');
                                //var fIds = getIdFromGrid(node, 'Id');
                                ajaxCalled(null, '../Service/HousePersonAddService.aspx?Action=DeletePerson', id, editGrid, null);
                            }

                        })
                    }
                }
            }
        }, '-', {
            text: '查看/编辑车辆',
            iconCls: 'edit',
            id: 'editCarDetail',
            tooltip: {
                text: '编辑人员车辆',
                title: '编辑人员车辆',
                autoHide: true
            },
            handler: function () { editGrid.onAddCarClick(baseInfoGrid.form.getValues().CreatePoliceManNumber,2); }
        }, '-', {
            text: '查看人员详细信息',
            iconCls: 'Check',
            id: 'CheckPersonDetail',
            tooltip: {
                text: '查看人员详细信息',
                title: '查看人员详细信息',
                autoHide: true
            },
            handler: function () { editGrid.onCheckPeopleDetailsClick(); }
        }, '-', {
            text: '查看历史住迹',
            iconCls: 'checkhis',
            tooltip: {
                text: '查看历史住迹',
                title: '查看历史住迹',
                autoHide: true
            },
            handler: function () {
                btnCarEnable = false;
                Ext.getCmp('deleteDetail').setDisabled(true);
                Ext.getCmp('addHousePerson').setDisabled(true);
                Ext.getCmp('editHousePerson').setDisabled(true); 
                editGrid.onPersonHistryCheckClick(houseId, 'HouseHold');
             }
        }, '-', {
            text: '查看现住人员',
            iconCls: 'checknow',
            tooltip: {
                text: '查看现住人员',
                title: '查看现住人员',
                autoHide: true
            },
            handler: function () {
                btnCarEnable = true;
                Ext.getCmp('deleteDetail').setDisabled(false);
                Ext.getCmp('addHousePerson').setDisabled(false);
                Ext.getCmp('editHousePerson').setDisabled(false); 
                editGrid.onPersonNowCheckClick(houseId, 'HouseHold');
              }
        }]
    });
    this.HousePersonEditGrid = editGrid;
  
    this.items = [{
        columnWidth: 1,
        border: false,
        items: [baseInfoGrid]
    },{
        columnWidth: 1,
        border: false,
        items: [editGrid]
    }];
    FantastPlatform.UI.HousePersonAddPanel.superclass.constructor.call(this, {
        layout: 'column',
        border: false
    });
};


Ext.extend(FantastPlatform.UI.HousePersonAddPanel, Ext.Panel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.HousePersonAddPanel.superclass.onRender.call(this, ct, position);
        if (this.Id && this.Id != 0) {
            this.HousePersonAddForm.add(new Ext.form.Hidden({ name: 'Id', value: this.Id }));
            var grid = this.HousePersonEditGrid;
            var gridId = this.Id;
            var bform = this.HousePersonAddForm;
            this.HousePersonAddForm.load({
                url: '../Service/HousePersonAddService.aspx?Action=Get',
                params: { id: this.Id },
                waitMsg: '正在读取数据...',
                waitTitle: '请稍后',
                success: function (form, action) {
//                    if (form.getValues().CreatePoliceManNumber != policemanNumber) {
//                        Ext.getCmp('deleteDetail').setDisabled(true);
//                        Ext.getCmp('addHousePerson').setDisabled(true);
//                        Ext.getCmp('editHousePerson').setDisabled(true);                      
//                    }
                    grid.store.removeAll();
                    grid.store.proxy.conn = { method: 'post', url: '../Service/PersonService.aspx?Action=GetPersonByHouseHold' };
                    grid.store.baseParams = { id: gridId };
                    grid.store.load({ params: { start: 0, limit: grid.paperBar.defaultNum, dir: '', sort: ''} });
                },
                failure: function (form, action) {
                    if (action.failureType != 'client') {
                        showErrorMessage('操作失败', action.result.message, '');
                    }
                }
            })
        }
    }

});  